<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE html>
<html>
<head>
<title>trace管理</title>
<jsp:include page="../inc.jsp"></jsp:include>


<script type="text/javascript">
	var dataGrid;
	$(function() {
		dataGrid = $('#dataGrid').datagrid({
			url : '${pageContext.request.contextPath}/transportController/tracedataGrid',
			fit : true,
			pagination : true,
			border : false,
			idField : 'id',
			fitColumns : false,
			remoteSort:false,
			pageSize : 50,
			pageList : [ 10, 20, 30, 40, 50 ],
			sortName : 'code',
			sortOrder : 'asc',
			checkOnSelect : true,
			selectOnCheck : true,
			nowrap : false,
			queryParams: {
				status: 'NONE',
			},
			frozenColumns : [ [ {
				field : 'id',
				title : '编号',
				width : 50,
				sortable : true,
				checkbox : true
			}, {
				field : 'code',
				title : '订单号',
				width : 200,
				sortable : true 
			} ] ],
			columns : [ [ {
				field : 'status',
				title : '状态',
				width : 200,
				sortable : true,
				formatter : function(value, row, index) {
					switch (value) {
					case 'NEW':
						return '新建';
					case 'SHIP':
						return '发货';
					case 'ARRIVE':
						return '到货';
					}
				}
			},{
				field : 'type',
				title : '类型',
				width : 200,
				sortable : true,
				formatter : function(value, row, index) {
					switch (value) {
                        case 'LAND':
                            return '陆运';
                        case 'AIR':
                            return '空运';
                        case 'SEA':
                            return '海运';
					}
				}
			},{
				field : 'sendRemark',
				title : '发货备注',
				width : 200,
				sortable : true,
			}] ],
			toolbar : '#toolbar',
			onDblClickRow: function(index,row){
				window.open("${pageContext.request.contextPath}/business/traceDetail.jsp?id="+row.id);
				parent.$.messager.progress('close');
				},
			onLoadSuccess : function() {
				$('#searchForm table').show();
				parent.$.messager.progress('close');

				$(this).datagrid('tooltip');
			},
			onRowContextMenu : function(e, rowIndex, rowData) {
				e.preventDefault();
				$(this).datagrid('selectRow', rowIndex);
				$('#menu').menu('show', {
					left : e.pageX,
					top : e.pageY
				});
			}
		});
	});

	
	
	//批量填写在途监控
	function onloadshadow() {
	var rows = dataGrid.datagrid('getChecked');
	var transportIds = [];
	
	if (rows.length > 0) {
				for ( var i = 0; i < rows.length; i++) {
					transportIds.push(rows[i].id);
				}
			var p = parent.$.modalDialog({
			 title : '在途跟踪',
			href : '${pageContext.request.contextPath}/traceController/traceDetailAdd',
			width : 450,
			height : 250, 
			buttons : [ {
				text : '在途监控录入',
				handler : function() {
					var f = p.find('form');
					f.form('submit', {
						url : '${pageContext.request.contextPath}/traceController/add',
						
						success : function(d) {
							
							var json = $.parseJSON(d);
							if (json.success) {
								dataGrid.datagrid('reload');
								p.dialog('close');
							}
							parent.$.messager.show({
								msg : json.msg,
								title : '提示',
								
							}); 
						}
					});
				}
			} ],
			onLoad : function() {
				var f = p.find('form');					
				f.form('load', {
					transportIds : transportIds.join(',')
				});
			}
		});
	}else {
		$.messager.alert('提示', '请勾选要在途跟踪的记录！', 'error');
	} 
}
	function searchFun(e) {
		dataGrid.datagrid('load', $.serializeObject($('#searchForm')));
	}
	function cleanFun() {
		$('#searchForm input').val('');
		dataGrid.datagrid('load', {});
	}
	
</script>
</head>
<body>
	<div class="easyui-layout" data-options="fit : true,border : false">
		<div data-options="region:'north',title:'查询条件',border:false" style="height: 60px; overflow: hidden;">
			<form id="searchForm">
				<table class="table table-hover table-condensed" style="display: none;">
					<tr>
						<th>订单号</th>
						<td><input name="codes" placeholder="支持模糊查询订单号" class="span2" onkeydown="if(event.keyCode==13 || event.which==13){searchFun(event);}"/></td>
						<td><input name="status"  value="NONE" class="span2" hidden="true"/></td>
					</tr>

				</table>
			</form>
		</div>
		<div data-options="region:'center',border:false">
			<table id="dataGrid"></table>
		</div>
	</div>
	<div id="toolbar" style="display: none;">
		
		<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'brick_add',plain:true" onclick="searchFun(event);">查询</a><!-- <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'brick_delete',plain:true" onclick="cleanFun();">清空条件</a> -->
	</div>

	<div id="menu" class="easyui-menu" style="width: 120px; display: none;">
	
		<c:if test="${fn:contains(sessionInfo.resourceList, '/traceController/traceDetailAdd')}">
			<div onclick="onloadshadow()" data-options="iconCls:'pencil_delete'">在途追踪</div>
		</c:if>
	</div>
</body>
</html>